package useTool;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.util.concurrent.Callable;

import standard.Standard;

public class ThreadListener implements Callable<Object> {
	private Socket socket;
	private String name;
	private static volatile boolean stop = false;
	
	public ThreadListener(Socket socket, String name)
	{
		this.socket=socket;
		this.name=name;
	}	
	@Override
	public Object call() throws Exception
	{
		Standard standard = null;
		Object return_object = null;
		while(!ThreadListener.stop)
		{
//			System.out.println("For testing 3");
			try {
				InputStream is = this.socket.getInputStream();
				if(is.available()!=0)
				{
					is = socket.getInputStream();
					byte[] s = new byte[1024];
					int len2 = is.read(s);
					ByteArrayInputStream  TransferBackToS = new ByteArrayInputStream(s); 
					ObjectInputStream in2 = new ObjectInputStream(TransferBackToS);
					return_object = (Object)in2.readObject();
					ThreadListener.stop = true;
					return return_object;
				}
			}catch(IOException e)
			{
				e.printStackTrace();
			}catch(ClassNotFoundException e ) {
				e.printStackTrace();
			}
		}
		return return_object;
	}
}
